home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / CPUTZ4P.C < prev    next >
C/C++ Source or Header  |  1992-08-18  |  4KB  |  104 lines

  1. /* cputz4p.c  -  Decoding image in Z4Plane format to VRAM, CHAINED mode.
  2.  *
  3.  * Description:
  4.  *   Uses the coding method, described in mputz4p.c
  5.  * See Also:
  6.  *      mputz4p.c, uputz4p.c
  7.  * Functions:
  8.  *      CputZ4Planes().
  9.  * Portability: BORLANDC
  10.  *                                      (c) erdy 1992
  11.  * $Header: $
  12.  */
  13. #pragma inline
  14. #include "far.h"
  15. #include "vgaprefx.h"
  16. #include "vgadrv.h"
  17. #include "screen.h"
  18.  
  19.  
  20. void CputZ4Planes(char far *image, unsigned x, unsigned y, int rows)
  21.         /* in case of ZC_PREPARED x is unused, y contains VRAM offset.
  22.          */
  23. {
  24.         _ES = Scdraw_seg;
  25.  
  26.     asm push ds;
  27.     asm lds si, image;
  28.     asm cld;
  29. #       ifdef ZC_PREPARED
  30.                 asm mov di, y;
  31. #       else  ZC_PREPARED
  32.                 _DI = VIDEO_CADDRESS(x, y);
  33. #       endif ZC_PREPARED
  34.  
  35.         asm mov dx, rows;
  36.         asm push bp;
  37.         asm mov cx, BITPLANES;
  38. PlaneLoop:
  39.         /*
  40.          * Planes loop.
  41.          * CX contains plane counter.
  42.          * DX contains row counter.
  43.          */
  44.         asm push cx;                    /* Save plane counter */
  45.         asm push di;                    /* Save starting offset */
  46.         asm mov  cx, dx;                /* Store row counter in cx */
  47. RowLoop:
  48.                 /*
  49.                  * Scanlines loop. CX contains nrows.
  50.                  * Scratch registers:
  51.                  *      bx - saving the ram index (di)
  52.                  *      bp - saving the loop counter (cx)
  53.                  */
  54.                 asm mov bx, di;                 /* Save ram index */
  55.                 asm mov bp, cx;                 /* Save loop counter */
  56.                 asm xor ch, ch;                 /* Zero high byte, ch always zero */
  57.                 /* Loop until EOL */
  58.                 asm jmp short LineLoop;         /* Jump over the literal-dealing code */
  59.                                                 /* This tricky is for optimizing jumps */
  60. Literal:
  61.                         asm movsb;              /* Copy cx bytes */
  62.                         asm add di, BITPLANES-1;
  63.                         asm loop Literal;
  64. LineLoop:
  65.             asm lodsb;              /* al <- ds:[si++]; get next byte */
  66.                         asm mov cl, al;         /* Move code */
  67.  
  68.                         asm or al, al;          /* Query flags */
  69.                         asm jg Literal;         /* al > 0, so literally */
  70.                         asm je short String;    /* al == 0, string or EOL */
  71. Skip:                                           /* Otherwise skipping */
  72.                         asm neg cl;             /* Invert counter */
  73.                         asm jo Eol;             /* Overflow, i.e. neg 128 */
  74.                         asm shl cx, 1;          /* Mul by 4 */
  75.                         asm shl cx, 1;
  76.                         asm add di, cx;         /* Advance the index */
  77.                         asm xor ch, ch;         /* Zero high byte, ch always zero */
  78.                         asm jmp short LineLoop;
  79. String:
  80.                         asm lodsb;              /* Get counter byte */
  81.             asm mov cl, al;        /* Put counter to cl */
  82.                         asm lodsb;              /* Get color byte into al */
  83. Sloop:
  84.                         asm stosb;              /* Store cx bytes of al */
  85.                         asm add di, BITPLANES-1;
  86.                         asm loop Sloop;
  87.  
  88.                         asm jmp short LineLoop;
  89. Eol:
  90.         asm mov di, bx;                 /* Restore ram index */
  91.                 asm add di, BPERROW_CHAINED;            /* Advance ram index to next row */
  92.  
  93.         asm mov cx, bp;                 /* Restore row counter */
  94.         asm loop RowLoop;
  95.  
  96.     asm pop di;             /* Restore the initial offset */
  97.         asm inc di;             /* Next bitplane */
  98.         asm pop cx;             /* Restore loop counter */
  99.         asm loop PlaneLoop;
  100.  
  101.         asm pop bp;
  102.     asm pop ds;
  103.     return;
  104. }